<template>
  <el-dialog
    :visible.sync="visible"
    title="拒绝内容"
    width="800"
    @before-close="onBeforeClose"
    @close="QualityDialogClose"
  >
    <section ref="print">
      <el-form
        ref="ruleForm"
        :model="ruleForm"
        :rules="rules"
        label-position="left"
        label-width="100px"
      >
        <el-form-item label="处理人" prop="handleMan">
          <el-input v-model="ruleForm.handleMan" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="处理备注" prop="handleNote">
          <el-input v-model="ruleForm.handleNote" :rows="2" placeholder="请输入内容" type="textarea" />
        </el-form-item>
        <!-- <el-form-item label="收货人" prop="receiveMan">
          <el-input v-model="ruleForm.receiveMan" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="收货备注" prop="receiveNote">
          <el-input v-model="ruleForm.receiveNote" :rows="2" placeholder="请输入内容" type="textarea" />
        </el-form-item>
        <el-form-item label="退款金额" prop="returnAmount">
          <el-input v-model="ruleForm.returnAmount" placeholder="请输入内容" />
        </el-form-item>-->
      </el-form>
    </section>
    <span slot="footer" class="dialog-footer">
      <el-button @click="QualityDialogClose">取 消</el-button>
      <el-button type="primary" @click="submitForm('ruleForm')">确 定</el-button>
    </span>
  </el-dialog>
</template>
<script>
export default {
  props: {
    quality: {
      type: Boolean,
      default: false
    },
    refuseItem: {
      type: Object,
      default: null
    }
  },
  data() {
    return {
      refuseItem2: null,
      ruleForm: {
        companyAddressId: '',
        handleMan: '',
        handleNote: '',
        id: '',
        receiveMan: '',
        receiveNote: '',
        returnAmount: '',
        status: '3'
      },
      visible: this.quality,
      rules: {
        handleMan: [
          { required: true, message: '请填写处理人', trigger: 'blur' }
        ],
        handleNote: [
          { required: true, message: '请填写收货人', trigger: 'blur' }
        ]
        // receiveMan: [
        //   { required: true, message: '请填写收货备注', trigger: 'blur' }
        // ],
        // returnAmount: [
        //   { required: true, message: '请填写退款金额', trigger: 'blur' }
        // ]
      }
    }
  },
  watch: {
    quality() {
      this.visible = this.quality
    },
    refuseItem() {
      this.refuseItem2 = this.refuseItem
    }
  },
  methods: {
    QualityDialogClose() {
      this.$emit('update:quality', false)
    },
    submitForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          const refuseItem2 = this.refuseItem2
          const data = {
            companyAddressId: refuseItem2.address.addressId,
            id: refuseItem2.refundId
          }
          this.ruleForm = Object.assign(this.ruleForm, data)
          this.$emit('onRefuseComment', this.ruleForm)
          this.QualityDialogClose()
        } else {
          return false
        }
      })
    },
    resetForm(formName) {
      this.$refs[formName].resetFields()
    },
    onBeforeClose() {
      this.resetForm('ruleForm')
    }
  }
}
</script>
